<template>
    <div class="pages">
        <div class="container" v-for="parent in state">
            <div class="title">
                <div class="line"></div>
                <div class="text" v-text="parent.title"></div>
            </div>
            <div class="function">
                <div class="item" v-for="item in parent.content" @click="clickHandle(item.to)">
                    <div class="container">
                        <div class="bg">
                            <img :src="item.icon" class="img">
                        </div>
                        <p class="content">{{item.title}}</p>
                    </div>

                    <div class="line"></div>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>

import iconZlrw from '@/assets/imgs/workbench/wb_order.png'
import iconRwck from '@/assets/imgs/workbench/wb_task_watch.png'
import iconHgts from '@/assets/imgs/workbench/wb_waring.png'
import iconTjbb from '@/assets/imgs/workbench/wb_report.png'
import iconSbfq from '@/assets/imgs/workbench/wb_user_report.png'
import iconJsspck from '@/assets/imgs/workbench/wb_abandon.png'
import iconZccx from '@/assets/imgs/workbench/wb_policy_watch.png'
import iconFlfgcx from '@/assets/imgs/workbench/wb_law.png'
import iconRwtj from '@/assets/imgs/workbench/wb_task_statistics.png'
import iconYjtj from '@/assets/imgs/workbench/wb_detect.png'
import iconBmyh from '@/assets/imgs/workbench/wb_user_statistics.png'
import iconsbck from '@/assets/imgs/workbench/wb_report_watch.png'
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router';
import { User, useStore } from '@/store'
const router = useRouter()
const store = useStore()

const state = ref([{
        title: "常用功能",
        content: [{
            title: '指令任务',
            icon: iconZlrw,
            to:'/orderTask'
        }, {
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }, {
            title: '上报查看',
            icon: iconsbck,
            to:'/reportpreview'
        }]
    }, {
        title: "任务发送",
        content: [{
            title: '指令任务',
            icon: iconZlrw,
            to:'/orderTask'
        }, {
            title: '合规提示',
            icon: iconHgts,
            to:'/compliance'
        }, {
            title: '统计报表',
            icon: iconTjbb,
            to:'/statistics'
        }, {
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }]
    }, {
        title: "主动报告",
        content: [{
            title: '上报发起',
            icon: iconSbfq,
            to:'/report'
        }, {
            title: '上报查看',
            icon: iconsbck,
            to:'/reportpreview'
        }]
    }, {
        title: "企业服务",
        content: [{
            title: '禁售商品词库',
            icon: iconJsspck,
            to:'/banned'
        }]
    }, {
        title: "政策与法律法规",
        content: [{
            title: '政策查询',
            icon: iconZccx,
            to:'/policy'
        }, {
            title: '法律法规查询',
            icon: iconFlfgcx,
            to:'/law'
        }]
    }, {
        title: "数据统计",
        content: [{
            title: '任务统计',
            icon: iconRwtj,
            to:'/taskcensus'
        }, {
            title: '依据统计',
            icon: iconYjtj,
            to:'/basiscensus'
        }, {
            title: '部门与用户统计',
            icon: iconBmyh,
            to:'/department'
        }]
    }] as any)

const clickHandle = (routePath: string) => {
    router.push(routePath);
}
// 处理用户权限
const handleUserPermission = () => {
    const userInfo = store.getters.getUser as User
    console.log('当前用户角色'+userInfo)
    const role = userInfo.roleCode[userInfo.roleCode.length-1]
    if(role === 'qy'){
        state.value =[{
        title: "常用功能",
        content: [{
            title: '上报发起',
            icon: iconSbfq,
            to:'/report'
        }, {
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }, {
            title: '上报查看',
            icon: iconsbck,
            to:'/reportpreview'
        }]
    }, {
        title: "任务发送",
        content: [{
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }]
    }, {
        title: "主动报告",
        content: [{
            title: '上报发起',
            icon: iconSbfq,
            to:'/report'
        }, {
            title: '上报查看',
            icon: iconsbck,
            to:'/reportpreview'
        }]
    }, {
        title: "企业服务",
        content: [{
            title: '禁售商品词库',
            icon: iconJsspck,
            to:'/banned'
        }]
    }, {
        title: "政策与法律法规",
        content: [{
            title: '政策查询',
            icon: iconZccx,
            to:'/policy'
        }, {
            title: '法律法规查询',
            icon: iconFlfgcx,
            to:'/law'
        }]
    }]
     
    }else if(role === 'zj'){
        state.value = [{
        title: "常用功能",
        content: [{
            title: '指令任务',
            icon: iconZlrw,
            to:'/orderTask'
        }, {
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }, {
            title: '上报查看',
            icon: iconsbck,
            to:'/reportpreview'
        }]
    }, {
        title: "任务发送",
        content: [{
            title: '指令任务',
            icon: iconZlrw,
            to:'/orderTask'
        }, {
            title: '合规提示',
            icon: iconHgts,
            to:'/compliance'
        }, {
            title: '统计报表',
            icon: iconTjbb,
            to:'/statistics'
        }, {
            title: '任务查看',
            icon: iconRwck,
            to:'/taskpreview'
        }]
    }, {
        title: "企业服务",
        content: [{
            title: '禁售商品词库',
            icon: iconJsspck,
            to:'/banned'
        }]
    }, {
        title: "政策管理",
        content: [{
            title: '政策查询',
            icon: iconZccx,
            to:'/policy'
        }, {
            title: '法律法规查询',
            icon: iconFlfgcx,
            to:'/law'
        }]
    }, {
        title: "数据统计",
        content: [{
            title: '任务统计',
            icon: iconRwtj,
            to:'/taskcensus'
        }, {
            title: '依据统计',
            icon: iconYjtj,
            to:'/basiscensus'
        }, {
            title: '部门与用户统计',
            icon: iconBmyh,
            to:'/department'
        }]
    }]
    }
}

onMounted(()=>{
    //移除工作台状态数据
    localStorage.removeItem('orderTask')
    //移除模板编辑状态数据
    localStorage.removeItem('model')
    //移除存储模板id
    localStorage.removeItem('modelId')
    console.log(store.getters.getUser)
    handleUserPermission()
})

</script>
<style lang="scss" scoped>
.pages {
    padding: 12px;
    box-sizing: border-box;
    height: auto;

    .title {
        display: flex;
        align-items: center;

        .line {
            width: 4px;
            height: 16px;
            margin-right: 8px;
            background-color: $primary-color;
        }

        .text {
            font-weight: 700;
            text-align: left;
            color: #181818;
            line-height: 12px;
            font-size: 18px;
        }
    }

    .function {
        background: #ffffff;
        border-radius: 5px;
        box-shadow: 0.5px 0.87px 4.5px 1px rgba(0, 0, 0, 0.05);
        display: flex;
        align-items: center;
        justify-content: left;
        flex-wrap: wrap;
        margin: 16px 0;
        .item {
            display: flex;
            flex-direction: row;
            align-items: center;
            padding: 16px 0;
            width: 33.33%;

            .container {
                width: 100%;
                display: flex;
                flex-direction: column;
                align-items: center;

                .bg {
                    width: 36px;
                    height: 36px;
                    background: #f1f4ff;
                    border-radius: 5px;
                    display: flex;
                    align-items: center;
                    justify-content: center;

                    img {
                        width: 16px;
                        height: 16px;
                    }
                }

                .content {
                    font-size: 10px;
                    font-weight: bold;
                    text-align: center;
                    color: #181818;
                    margin-top: 8px;
                }
            }


            .line {
                width: 0.5px;
                height: 34px;
                background: #ececec;
                text-align: right;
            }
        }
    }
}
</style>